package com.oazon.moco.link.serialport;

import java.util.Arrays;

import com.oazon.moco.link.core.LinkEvent;
import com.oazon.moco.link.core.LinkEventListener;
import com.oazon.moco.link.core.source.LinkEventSource;
import com.oazon.moco.link.event.RequestEvent;
import com.oazon.moco.link.event.RequestStatus;
import com.oazon.moco.serialport.SerialSend;




public class RequestEventListener extends LinkEventListener {

	public RequestEventListener(LinkEventSource... sources) {
		setBlackList(Arrays.asList(sources));
	}

	@Override
	public void onLinkEvent(LinkEvent event) {
		if(filter((LinkEventSource)event.getSource()) || !(event instanceof RequestEvent)){
			return;
		}
		RequestEvent e = (RequestEvent)event;
	
		if(e.getRequestStatus()==RequestStatus.HARDWARE_VERSION)
		{
			SerialSend.getInstance().sendStatus(SerialSend.Serial_HARDWAREVERSION);
		}else
    	if(e.getRequestStatus()==RequestStatus.CHARGE){
    		SerialSend.getInstance().sendStatus(SerialSend.Serial_POWER_CHARGE);
    	}else
    	if(e.getRequestStatus()==RequestStatus.FULL){
    		SerialSend.getInstance().sendStatus(SerialSend.Serial_POWER_FULL);
    	}else
        if(e.getRequestStatus()==RequestStatus.PERCENT){
        	SerialSend.getInstance().sendStatus(SerialSend.Serial_POWER_PERCENT);
       } else
        if(e.getRequestStatus()==RequestStatus.EXTERNAL_BATTERY_IN){
        	SerialSend.getInstance().sendStatus(SerialSend.Serial_POWER_EXTERNAL);
       }
	}	
}
